package collection;

import org.junit.Test;

import java.util.*;

/**
 * @author lwmzzz
 * @version 1.0
 * @date 2021/3/28 21:01
 * @description Collection类test
 */
public class CollectionTest {
    @Test
    public void test() {
        List<String> strings = new ArrayList<>();
        //equals方法
        System.out.println(strings.contains("1"));
        List<String> stringList = new ArrayList<>(100);
        System.out.println(stringList.size());
    }

    @Test
    public void test1() {
        List<String> strings = new LinkedList<>();
        strings.add("a");
        strings.add("d");
        strings.add("c");
        strings.add("b");
        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            if (next.equals("c")) {
                iterator.remove();
            }
        }
        System.out.println(strings);

        //底层调用迭代器
        for (String string : strings) {
            System.out.println(string);
        }
    }

    @Test
    public void test2() {
        String a = "123";
        //String 是final 不可变性
        String[] str = new String[5];
        for (String s : str) {
            s = a;
            System.out.println(s);
        }
        for (int i = 0; i < str.length; i++) {
            System.out.println(str[i]);
        }
    }

    @Test
    public void test3() {
        List list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
//        list.remove(2);
        //参数为对象/下标(int)
        list.remove(new Integer(2));
        System.out.println(list);
    }

    @Test
    public void test4() {
        List lists = new Vector();
        lists.add("1");
        List<String> list = new ArrayList<>();
        List list1 = new LinkedList();
        list.add("q");
        List<String> strings = Arrays.asList("a", "b");
    }


}
